﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:params="http://schemas.codeplex.com/elysium/params"
                    xmlns:controls="clr-namespace:Framework.UI.Controls">
    <ResourceDictionary.MergedDictionaries>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Converter.xaml"/><controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Brush.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/ElysiumExtra/BorderFix.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="ScrollBarLineDownButtonStyle" TargetType="{x:Type RepeatButton}" >
        <Setter Property="Background" Value="{StaticResource TransparentBrush}" />
        <Setter Property="BorderBrush" Value="{StaticResource MiddleLightBrush}" />
        <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Self},Path=(params:General.DefaultThickness),Mode=OneWay}" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <controls:BorderFix Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Polygon Points="0,0 3,4 6,0" 
                                 Fill="{TemplateBinding BorderBrush}" 
                                 StrokeThickness="0" 
                                 Stretch="Uniform" 
                                 Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type ScrollBar}},Path=(params:ScrollBar.ArrowSize),Mode=OneWay}" 
                                 Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type ScrollBar}},Path=(params:ScrollBar.ArrowSize),Mode=OneWay}"/>
                    </controls:BorderFix>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="BorderBrush" Value="{StaticResource LowlightBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="BorderBrush" Value="{StaticResource ForegroundBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource DisabledBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style x:Key="ScrollBarLineUpButtonStyle" TargetType="{x:Type RepeatButton}" BasedOn="{StaticResource ScrollBarLineDownButtonStyle}" >
        <Setter Property="LayoutTransform">
            <Setter.Value>
                <RotateTransform Angle="180" />
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="ScrollBarLineLeftButtonStyle" TargetType="{x:Type RepeatButton}" BasedOn="{StaticResource ScrollBarLineDownButtonStyle}" >
        <Setter Property="LayoutTransform">
            <Setter.Value>
                <RotateTransform Angle="-90" />
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="ScrollBarLineRightButtonStyle" TargetType="{x:Type RepeatButton}" BasedOn="{StaticResource ScrollBarLineDownButtonStyle}" >
        <Setter Property="LayoutTransform">
            <Setter.Value>
                <RotateTransform Angle="90" />
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="ScrollBarPageButtonStyle" TargetType="{x:Type RepeatButton}" >
        <Setter Property="Background" Value="{StaticResource TransparentBrush}" />
        <Setter Property="BorderBrush" Value="{StaticResource TransparentBrush}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="ScrollBarThumbStyle" Style.TargetType="{x:Type Thumb}" >
        <Setter Property="Background" Value="{StaticResource MiddleLightBrush}" />
        <Setter Property="BorderBrush" Value="{StaticResource TransparentBrush}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False" />
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self},Path=(params:General.DefaultPaddingValue),Mode=OneWay,Converter={StaticResource DoubleToThicknessConverter},ConverterParameter=Left}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Grid SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Border Background="{TemplateBinding Background}" 
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                Margin="{TemplateBinding Padding}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{StaticResource LowlightBrush}" />
            </Trigger>
            <Trigger Property="IsDragging" Value="True">
                <Setter Property="Background" Value="{StaticResource ForegroundBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Background" Value="{StaticResource DisabledBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    <ControlTemplate x:Key="HorizontalScrollBarTemplate" TargetType="{x:Type ScrollBar}" >
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <RepeatButton Grid.Column="0" 
                              Command="{x:Static ScrollBar.LineLeftCommand}" 
                              IsEnabled="{TemplateBinding IsEnabled}" 
                              Style="{StaticResource ScrollBarLineLeftButtonStyle}" 
                              Visibility="Collapsed" />
                <Track x:Name="PART_Track" 
                       Grid.Column="1">
                    <Track.DecreaseRepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.PageLeftCommand}" 
                                      IsEnabled="{TemplateBinding IsEnabled}" 
                                      Style="{StaticResource ScrollBarPageButtonStyle}" />
                    </Track.DecreaseRepeatButton>
                    <Track.Thumb>
                        <Thumb IsEnabled="{TemplateBinding IsEnabled}" 
                               Style="{StaticResource ScrollBarThumbStyle}" />
                    </Track.Thumb>
                    <Track.IncreaseRepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.PageRightCommand}" 
                                      IsEnabled="{TemplateBinding IsEnabled}" 
                                      Style="{StaticResource ScrollBarPageButtonStyle}" />
                    </Track.IncreaseRepeatButton>
                </Track>
                <RepeatButton Grid.Column="2" 
                              Command="{x:Static ScrollBar.LineRightCommand}" 
                              IsEnabled="{TemplateBinding IsEnabled}" 
                              Style="{StaticResource ScrollBarLineRightButtonStyle}" 
                              Visibility="Collapsed" />
            </Grid>
        </Border>
    </ControlTemplate>
    <ControlTemplate x:Key="VerticalScrollBarTemplate" TargetType="{x:Type ScrollBar}" >
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <RepeatButton Grid.Row="0" 
                              Command="{x:Static ScrollBar.LineUpCommand}" 
                              IsEnabled="{TemplateBinding IsEnabled}" 
                              Style="{StaticResource ScrollBarLineUpButtonStyle}" 
                              Visibility="Collapsed" />
                <Track x:Name="PART_Track" 
                       Grid.Row="1" 
                       IsDirectionReversed="True">
                    <Track.DecreaseRepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.PageUpCommand}" 
                                      IsEnabled="{TemplateBinding IsEnabled}" 
                                      Style="{StaticResource ScrollBarPageButtonStyle}" />
                    </Track.DecreaseRepeatButton>
                    <Track.Thumb>
                        <Thumb IsEnabled="{TemplateBinding IsEnabled}" 
                               Style="{StaticResource ScrollBarThumbStyle}" />
                    </Track.Thumb>
                    <Track.IncreaseRepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.PageDownCommand}" 
                                      IsEnabled="{TemplateBinding IsEnabled}" 
                                      Style="{StaticResource ScrollBarPageButtonStyle}" />
                    </Track.IncreaseRepeatButton>
                </Track>
                <RepeatButton Grid.Row="2" 
                              Command="{x:Static ScrollBar.LineDownCommand}" 
                              IsEnabled="{TemplateBinding IsEnabled}"
                              Style="{StaticResource ScrollBarLineDownButtonStyle}" 
                              Visibility="Collapsed" />
            </Grid>
        </Border>
    </ControlTemplate>
    <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource MiddleLightBrush}"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Stylus.IsFlicksEnabled" Value="false"/>
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Horizontal">
                <Setter Property="BorderThickness" Value="{Binding Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter=Bottom, Mode=OneWay, Path=(params:General.DefaultPaddingValue), RelativeSource={RelativeSource Self}}"/>
                <Setter Property="MinHeight" Value="12"/>
                <Setter Property="Height" Value="12"/>
                <Setter Property="MaxHeight" Value="10"/>
                <Setter Property="Template" Value="{StaticResource HorizontalScrollBarTemplate}"/>
            </Trigger>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="BorderThickness" Value="{Binding Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter=Right, Mode=OneWay, Path=(params:General.DefaultPaddingValue), RelativeSource={RelativeSource Self}}"/>
                <Setter Property="MinWidth" Value="12"/>
                <Setter Property="Width" Value="12"/>
                <Setter Property="MaxWidth" Value="10"/>
                <Setter Property="Template" Value="{StaticResource VerticalScrollBarTemplate}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>